<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回字段的名字</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.pg-field-name" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">pg_field_name</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">pg_field_name</span> &mdash; <span class="dc-title">返回字段的名字</span></p>

   </div>
   <div class="refsect1 unknown-unknown-seealsq" id="refsect1-function.pg-field-name-unknown-unknown-seealsq">
    <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>pg_field_name</strong></span>
       ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>
      , <span class="methodparam"><span class="type">int</span> <code class="parameter">$field_number</code></span>
      ) : <span class="type">string</span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>pg_field_name()</strong></span> 返回给定 PostgreSQL <code class="parameter">result</code> 资源中的 <code class="parameter">field_number</code> 所代表的字段名。字段编号从 0 开始。
    </p>
    <p class="para">
     <div class="example" id="example-2494">
      <p><strong>Example #1 获取字段信息</strong></p>
      <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;$dbconn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"select&nbsp;*&nbsp;from&nbsp;authors&nbsp;where&nbsp;author&nbsp;=&nbsp;'Orwell'"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_num_fields</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(</span><span style="color: #0000BB">$j&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$j&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$j</span><span style="color: #007700">++)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"column&nbsp;</span><span style="color: #0000BB">$j</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$fieldname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_field_name</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$j</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"fieldname:&nbsp;</span><span style="color: #0000BB">$fieldname</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"printed&nbsp;length:&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">pg_field_prtlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$fieldname</span><span style="color: #007700">).</span><span style="color: #DD0000">"&nbsp;characters\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"storage&nbsp;length:&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">pg_field_size</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$j</span><span style="color: #007700">).</span><span style="color: #DD0000">"&nbsp;bytes\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"field&nbsp;type:&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">pg_field_type</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$j</span><span style="color: #007700">).</span><span style="color: #DD0000">"&nbsp;\n\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
      </div>

      <div class="example-contents"><p>
       上例的输出如下：
      </p></div>
      <div class="example-contents screen">
<div class="cdata"><pre>
column 0
fieldname: author
printed length: 6 characters
storage length: -1 bytes
field type: varchar

column 1
fieldname: year
printed length: 4 characters
storage length: 2 bytes
field type: int2

column 2
fieldname: title
printed length: 24 characters
storage length: -1 bytes
field type: varchar
</pre></div>
      </div>
     </div>
    </p>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <p class="para">
      本函数以前的名字为 <em>pg_fieldname()</em>。
     </p>
    </p></blockquote>
    <p class="para">
     参见 <span class="function"><a href="pg_field_num.html" class="function">pg_field_num()</a></span>。
    </p>
   </div>

  </div></div></div></body></html>